package com.cxc.minio.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cxc.minio.entity.UserImage;
import com.cxc.minio.service.UserImageService;
import com.cxc.minio.mapper.UserImageMapper;
import org.apache.catalina.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Wrapper;

/**
* @author cxc
* @description 针对表【t_user_image】的数据库操作Service实现
* @createDate 2025-01-04 16:42:28
*/
@Service
public class UserImageServiceImpl extends ServiceImpl<UserImageMapper, UserImage>
    implements UserImageService{
    @Resource
    private UserImageMapper userImageMapper;

    @Override
    public boolean  saveOrUpdate(Integer uid,String bucketName,String objectName) {

        LambdaQueryWrapper<UserImage> wrapper = new LambdaQueryWrapper<UserImage>()
                .eq(UserImage::getUid,uid);
        long count = userImageMapper.selectCount(wrapper);
        boolean flag = false;
        UserImage userImage = new UserImage();
        userImage.setBucket(bucketName);
        userImage.setObject(objectName);
        userImage.setUid(uid);
        if (count<=0){
            userImage.setCreateTime(new java.util.Date());
            flag = userImageMapper.insert(userImage)>=1;
        }else {
            userImage.setUpdateTime(new java.util.Date());
            flag = userImageMapper.update(userImage,wrapper)>=1;
        }
        return flag;
    }


}




